home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / autopaint / moddir.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  112 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "vect.h"
  18. #include "math.h"
  19. #include "canvas.h"
  20.  
  21. #define DIRBLEND    0.30
  22. #define MINDELTA    10
  23.  
  24. float flerp();
  25.  
  26. extern int winxsize, winysize;
  27. static int origx, origy;
  28. static int lastx, lasty;
  29. static float curdirx, curdiry;
  30. static float startdirx, startdiry;
  31. static int dirsource = DIR_FOLLOW;
  32. static int waiting;
  33. static float curdir;
  34.  
  35. mousedown(x,y)
  36. int x, y;
  37. {
  38.     origx = lastx = x;
  39.     origy = lasty = y;
  40.     waiting = 1;
  41. }
  42.  
  43. mousemove(x,y)
  44. int x, y;
  45. {
  46.     float delta;
  47.     float dx, dy;
  48.     int inside;
  49.  
  50.     if(x<0 || x>winxsize || y<0 || y>winysize)
  51.     inside = 0;
  52.     else
  53.     inside = 1;
  54.     dx = x-lastx;
  55.     dy = y-lasty;
  56.     lastx = x;
  57.     lasty = y;
  58.     delta = fsqrt(dx*dx+dy*dy);
  59.     if(delta<1.0) {
  60.     if(waiting)
  61.         return 0;
  62.     else
  63.         return inside;
  64.     }
  65.     if(dirsource == DIR_FOLLOW || dirsource == DIR_FIRST) {
  66.     if(waiting) {
  67.         dx = x-origx+qrand();
  68.         dy = y-origy+qrand();
  69.         delta = fsqrt(dx*dx+dy*dy);
  70.         if(delta<MINDELTA)
  71.         return 0;
  72.         curdirx = dx;
  73.         curdiry = dy;
  74.         setdirection((360.0/(2*M_PI))*fatan2(curdiry,curdirx));
  75.         waiting = 0;
  76.     }
  77.     }
  78.     switch(dirsource) {
  79.     case DIR_FOLLOW:
  80.         dx = dx/delta;
  81.         dy = dy/delta;
  82.         if (((dx*curdirx)+(dy*curdiry))<0.0) {
  83.         dx = -dx;
  84.         dy = -dy;
  85.         }
  86.         curdirx = flerp(curdirx,dx,DIRBLEND);
  87.         curdiry = flerp(curdiry,dy,DIRBLEND);
  88.         setdirection((360.0/(2*M_PI))*fatan2(curdiry,curdirx));
  89.         return inside;
  90.         break;
  91.     case DIR_FIRST:
  92.         return inside;
  93.         break;
  94.     default:
  95.         return inside;
  96.         break;
  97.     }
  98. }     
  99.  
  100. setdirsource(mode)
  101. int mode;
  102. {
  103.     dirsource = mode;
  104. }
  105.  
  106. setdirection(dir)
  107. float dir;
  108. {
  109.     curdir = dir;
  110.     setangle(curdir+30.0*qrand());
  111. }
  112.